auto.waitFor();
//console.show();
var myFunc = require("./myCommonFunction.js");
sleep(2000);
opreate();

function opreate() {
    var ret = myFunc.initNetWork(null, true);
    if (ret) {
        pingduoduo();
    }
    myFunc.tuichu("拼多多");
    // myFunc.closeWifiOrData(true);
}

function pingduoduo() {
    myFunc.openMyApp("拼多多");
    var backWord = ['个人中心', '省钱月卡', '免费试用', '今日试用']
    var posIdx = -1;
    for (let index = 0; index < backWord.length; index++) {
        let word = backWord[index];
        if (myFunc.findOnce(word) != null) {
            posIdx = index;
            break
        }
    }
    // log(posIdx);
    switch (posIdx) {
        case 0:
            log("点击个人中心");
            myFunc.textpClick('个人中心', 5000)
            sleep(1000);
        case 1:
            log("点击月卡");
            myFunc.textpClick('省钱月卡', 5000)
            sleep(2500);
        case 2:
            log("点击试用");
            myFunc.clickTextByBtn('免费试用', 5000)
            sleep(3000);
        case 3:
            myFunc.findOne('今日试用')
            var tishengList = text("提升概率").find();
            log("获取提升:" + (tishengList != null));
            var appPackName = getPackageName("拼多多");

            for (let i = 0; i < tishengList.length; i++) {
                sleep(1000);
                tishengList[i].click();
                sleep(2000);
                var lingqu = text("去完成").find();
                while (text("去完成").findOne(1000) != null) {
                    myFunc.pClick(lingqu[0]);
                    sleep(33000);
                    launch(appPackName);
                    sleep(1000);
                    back();
                    sleep(5000);
                }
                // if (lingqu == null) {
                //     log("已完成");
                // } else {
                //     for (let i = 1; i < 6; i++) {
                //         log("开始第"+i+"次点击");
                //         myFunc.pClick(lingqu[0]);
                //         sleep(33000);
                //         launch(appPackName);
                //         sleep(1000);
                //         back();
                //         sleep(5000);
                //     }
                //     lingqu = text("去完成").find();
                //     if(lingqu.length > 0) {
                //         myFunc.pClick(lingqu[0]);
                //         sleep(33000);
                //         launch(appPackName);
                //         sleep(1000);
                //         back();
                //         sleep(1000);
                //     }
                // }
                back();
            }
            log("点击完成");
            break;
        default:
            myFunc.tuichu("拼多多");
            sleep(500);
            pingduoduo();
            break;
    }
}








